/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package maincz.tests.webapp.backingbeans;

import java.util.logging.Logger;
import javax.annotation.PostConstruct;
import javax.enterprise.context.SessionScoped;
import maincz.tests.webapp.utils.scheduling.IScheduler;
import maincz.tests.webapp.utils.scheduling.SchedulerManager;
import maincz.tests.webapp.utils.scheduling.SimpleScheduler;
import maincz.tests.webapp.utils.scheduling.actions.PrintInfoAction;
import maincz.tests.webapp.utils.scheduling.actions.WaitAction;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 *
 * @author Main
 */
@Component("threadTestBean")
@SessionScoped
public class ThreadTestsBean {
    
    private static final Logger log = Logger.getLogger("MujLog");

    @Autowired
    private SchedulerManager manager;
    
    public ThreadTestsBean() {
        super();
        log.info("ThreadTestsBean constructor");
    }
    
    @PostConstruct
    public void postConstruct() {
        manager.put("test1", new SimpleScheduler("FirstSimpleScheduler"));
        manager.put("test2", new SimpleScheduler("SecondSimpleScheduler"));
    }
    
    public void test() {
         log.info("testcontroller get");
        for (IScheduler scheduler: this.manager.values()) {
            log.info("planovac: " + scheduler.getName());
        }
        
        IScheduler scheduler = this.manager.get("test1");
        scheduler.pushAction(new WaitAction(1000));
        scheduler.pushAction(new PrintInfoAction("prvni meta"));
        scheduler.pushAction(new WaitAction(2000));
        scheduler.pushAction(new PrintInfoAction("druha meta"));
        scheduler.pushAction(new WaitAction(3000));
        scheduler.pushAction(new PrintInfoAction("treti meta"));
        scheduler.pushAction(new WaitAction(1000));
        scheduler.pushAction(new PrintInfoAction("ctvrta meta"));
        scheduler.pushAction(new WaitAction(5000));
        scheduler.pushAction(new PrintInfoAction("pata meta"));
        scheduler.pushAction(new WaitAction(1000));
        scheduler.pushAction(new PrintInfoAction("sesta meta"));
        scheduler.pushAction(new WaitAction(1000));
        scheduler.pushAction(new PrintInfoAction("posledni meta"));
        scheduler.start();
    }
}
